import version from '../common/js/url.js';
	
export default {
	methods: {
		// 查询用户钱包信息
		getUserMoney(){
			var data = null;
			this.$Ajax('/api/money/getUserMoney',
			data,
			res => {
					if (res.code == 200) {
						this.userMoney = res.data;
						// console.log("this.userMoney:",this.userMoney);
					}
				}
			)
		},
		// 查询用户实时最新信息
		getUserInfo(){
			var data = null;
			this.$Ajax('/api/user/getUserInfo',
			data,
			res => {
					if (res.code == 200) {
						this.userInfo = res.data;
						console.log("this.userInfo:",this.userInfo);
					}
				}
			)
		},
		// 查询七牛云上传文件TOKEN
		getQiNiuToken(){
			var data = {};
			this.$Ajax('/api/common/qiniu/token',
			data,
			res => {
					if (res.code == 200) {
						this.qiniu = res.data;
					}
				}, err => {
				}, 'GET', false
			)
		},
		// 查询系统参数
		getSystemParam(){
			var data = {};
			this.$Ajax('/api/common/getParam',
			data,
			res => {
					if (res.code == 200) {
						this.systemParam = res.data;
					}
				}, err => {
				}, 'GET'
			)
		},
		getKeyNumber(val) {
			let paymentPwdArr = this.paymentPwd.split('');
			if (val === '' || (val != -1 && paymentPwdArr.length === 6)) {
				if (paymentPwdArr.length === 6) {
					this.submit();
					return;
				}
				return false;
			} else if (val != -1) { //数字输入
				paymentPwdArr.splice(this.activeInput, 0, val);
				this.activeInput++;
				this.paymentPwd = paymentPwdArr.join('');
				if (paymentPwdArr.length === 6) {
					console.log(paymentPwdArr)
					this.submit();
					return;
				}
			} else { //删除
				if (this.activeInput >= 0) {
					this.activeInput !== 0 && this.activeInput--;
					paymentPwdArr.splice(this.activeInput - 1, 1);
					this.paymentPwd = paymentPwdArr.join('');
				}
			}
		},
		//获取url中的参数
		getParam(path, name) {
			var reg = new RegExp("(^|\\?|&)" + name + "=([^&]*)(\\s|&|$)", "i");
			if (reg.test(path))
			return unescape(RegExp.$2.replace(/\+/g, " "));
			return "";
		},
		getQueryString(name) {
			// var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
		    var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
		    var r = window.location.search.substr(1).match(reg);
		    if (r != null) {
		        return unescape(r[2]);
		    }
		    return null;
		},
		// 时间转为毫秒 
		timeToSec(time) {
		      var hour = time.split(':')[0]
		      var min = time.split(':')[1]
		      var sec = time.split(':')[2]
		      var s = Number(hour * 3600) + Number(min * 60) + Number(sec)
		      return s * 1000
		},
		getTime(dateBegin,dateEnd,dateNow){
			var beginDiff = dateNow - dateBegin;//时间差的毫秒数
			var beginDayDiff = Math.floor(beginDiff / (24 * 3600 * 1000));//计算出相差天数
			var endDiff = dateEnd - dateNow;//时间差的毫秒数
			var endDayDiff = Math.floor(endDiff / (24 * 3600 * 1000));//计算出相差天数       
			if (endDayDiff < 0) {//已过期
			    return 1
			}
			if (beginDayDiff < 0) {//没到开始时间
			    return 1;
			}
			return 2;
		},
		// 时间范围内（年月日时分秒）
		nowInDateBetwen(d1,d2,d3) {
		    //如果时间格式是正确的，那下面这一步转化时间格式就可以不用了
		     // var dateBegin = new Date(d1.replace(/-/g, "/"));//将-转化为/，使用new Date
		       // var dateEnd = new Date(d2.replace(/-/g, "/"));//将-转化为/，使用new Date
		    var dateBegin = new Date(d1);//将-转化为/，使用new Date
		    var dateEnd = new Date(d2);//将-转化为/，使用new Date
		    var dateNow = new Date(d3);//获取当前时间
			console.log("dateBegin：",dateBegin,"dateEnd：",dateEnd,"dateNow：",dateNow);
		    var beginDiff = dateNow.getTime() - dateBegin.getTime();//时间差的毫秒数       
		    var beginDayDiff = Math.floor(beginDiff / (24 * 3600 * 1000));//计算出相差天数
		
		    var endDiff = dateEnd.getTime() - dateNow.getTime();//时间差的毫秒数
		    var endDayDiff = Math.floor(endDiff / (24 * 3600 * 1000));//计算出相差天数       
		    if (endDayDiff < 0) {//已过期
		        return '即将开始'
		    }
		    if (beginDayDiff < 0) {//没到开始时间
		        return '即将开始';
		    }
		    return '竞拍中';
		},
		getEndTime(dayNum, dateTime) {
			// 如果为null,则格式化当前时间为时间戳
			// if (!dateTime) dateTime = +new Date();
			// // 如果dateTime长度为10或者13，则为秒和毫秒的时间戳，如果超过13位，则为其他的时间格式
			// if (dateTime.toString().length == 10) dateTime *= 1000;
			const timestamp = +new Date();
			const one_day = 86400000; // 24 * 60 * 60 * 1000;
			const addVal = dayNum * one_day + timestamp;
			//x天后的日期
			const date = new Date(addVal);
			//格式化日期
			const filters = n => {
				return n < 10 ? (n = '0' + n) : n;
			};
			const month = filters(date.getMonth() + 1);
			const day = filters(date.getDate());
			const hours = filters(date.getHours());
			const minutes = filters(date.getMinutes());
			const seconds = filters(date.getSeconds());
			const w = filters(date.getDay());
			const week="周"+"日一二三四五六".charAt(w);
			const lastTime = `${date.getFullYear()}-${month}-${day} ${dateTime}`;
			return lastTime;
		},
		getNextMonthSameDay(year, month, day) {
			console.log(year, month, day);
			var date = new Date(year, month, day); // 创建当前月份的日期对象
			date.setMonth(date.getMonth() + 1); // 设置下一个月
			// return {
			// 	year: date.getFullYear(), // 获取下个月的年份
			// 	month: date.getMonth(), // 获取下个月（0-11）
			// 	day: date.getDate() // 获取下个月的日
			// };
			return date.getFullYear()+''+ (Number(date.getMonth()) >= 10 ? date.getMonth() : '0'+date.getMonth()) 
			+''+ (Number(date.getDate()) >= 10 ? date.getDate() : '0'+date.getDate());
		},
		simplifyNum(number) {
			if (!number && number != 0) return number;
			var str_num
			if (number >= 1E3 && number < 1E4) {
				str_num = number / 1E3
				return str_num + '千'
			} else if (number >= 1E4 && number < 1E6) {
				str_num = number / 1E4
				return str_num + '万'
			} 
			else if (number >= 1E6 && number < 1E7) {
				str_num = number / 1E6
				return str_num + '百万'
			} else if (number >= 1E7 && number < 1E8) {
				str_num = number / 1E7
				return str_num + '千万'
			} 
			else if (number >= 1E8 && number < 1E10) {
				str_num = number / 1E8
				return str_num + '亿'
			} else if (number >= 1E10 && number < 1E11) {
				str_num = number / 1E10
				return str_num + '百亿'
			} else if (number >= 1E11 && number < 1E12) {
				str_num = number / 1E11
				return str_num + '千亿'
			} else if (number >= 1E12) {
				str_num = number / 1E12
				return str_num + '万亿'
			} else { //一千以下
				return number
			}
		},
		// 减法函数，用来得到精确的加法结果
		jian(arg2, arg1) {
			var r1, r2, m, n;
			try {
				r1 = arg1.toString().split(".")[1].length
			} catch (e) {
				r1 = 0
			}
			try {
				r2 = arg2.toString().split(".")[1].length
			} catch (e) {
				r2 = 0
			}
			m = Math.pow(10, Math.max(r1, r2));
			//lastmodifybydeeka  
			//动态控制精度长度  
			n = (r1 >= r2) ? r1 : r2;
			return ((arg2 * m - arg1 * m) / m).toFixed(n);
		},
		// 加法
		jia(arg1, arg2) {
			var r1, r2, m;
			try {
				r1 = arg1.toString().split(".")[1].length
			} catch (e) {
				r1 = 0
			}
			try {
				r2 = arg2.toString().split(".")[1].length
			} catch (e) {
				r2 = 0
			}
			m = Math.pow(10, Math.max(r1, r2));
			return (arg1 * m + arg2 * m) / m;
		},
		// 乘法函数
		cheng(arg1, arg2) {
			var m = 0,
				s1 = arg1.toString(),
				s2 = arg2.toString();
			try {
				m += s1.split(".")[1].length
			} catch (e) {}
			try {
				m += s2.split(".")[1].length
			} catch (e) {}
			return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m);
		},
		// 除法函数
		chu(arg1, arg2) {
			var t1 = 0,
				t2 = 0,
				r1, r2;
			try {
				t1 = arg1.toString().split(".")[1].length
			} catch (e) {}
			try {
				t2 = arg2.toString().split(".")[1].length
			} catch (e) {}
			r1 = Number(arg1.toString().replace(".", ""))
			r2 = Number(arg2.toString().replace(".", ""))
			return (r1 / r2) * Math.pow(10, t2 - t1);
		},
		toFloor(value) {
			return Math.floor(this.cheng(value, 100)) / 100
		},
		toFloor4(value) {
			return Math.floor(this.cheng(value, 10000)) / 10000
		}
	}
}
